<?php

namespace app\admin\controller;

use app\service\UserService;



class Profile extends Admin
{

    public function __construct(UserService $service)
    {
        parent::__construct();
        $this->service = $service;
    }

    public function info()
    {
        if (!$this->request->isPost()) {
            $vo = $this->service->get(UID);
            $this->assign("vo", $vo);
            return $this->fetch("info");
        }
        $params = $this->request->Post();
        $res = $this->service->saveAll($params);
        if (!$res) {
            $this->error("保存失败");
        }
        $this->success("保存成功");
    }

    /**
     * 修改密码
     * @return string|\think\response\Json
     * @throws ParameterException
     */
    public function passwd()
    {
        if (!$this->request->isPost()) {
            $vo = $this->service->get(UID);
            $this->assign("vo", $vo);
            return $this->fetch("passwd");
        }
        $params = $this->request->Post();
        $ret = $this->service->savePasswd($params);
        if ($ret) {
            $this->success("设置成功");
        } else {
            $this->error("设置失败");
        }
    }
}